#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e3+7;
ll a[N];
ll f[N][2],w[N][N];
int main(){
     freopen("color.in","r",stdin);
     freopen("color.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T; cin>>T;
    while(T--){
        memset(f,0,sizeof(f));
        memset(w,0,sizeof(w));
        
        ll n; cin>>n;
        
        for(int i=1;i<=n;i++) cin>>a[i];
        if(n>2000) continue;
        for(int i=0;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                ll xs=0;
                if(a[j]==a[j-1]) xs=1;
                w[i][j]=w[i][j-1]+xs*a[j];
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=0;j<i;j++){
                int xs=0;
                if(a[i]==a[j-1]&&j-1>=0) xs=1;
                f[i][0]=max(f[i][0],f[j][1]+xs*a[i]+w[j][i-1]);
                f[i][1]=max(f[i][1],f[j][0]+xs*a[i]+w[j][i-1]);
            }
        }
        ll ans=0;
        for(int i=0;i<=n;i++){
            ans=max(ans,f[i][0]+w[i][n]);
            ans=max(ans,f[i][1]+w[i][n]);
        }
        cout<<ans<<'\n';
    }
    return 0;
}